import router from "@/router"
export default {
  namespaced: true,
  state: {
    userName: null,
    token: null,
    timeout: '',
    userId: '',    // 用户id
    roleCode: '',  // 角色code
    regionId: '',  // 区域Id(运营、运维客户端专用)
  },
  mutations: {
    setStateToken(state, payload) {
      state.token = payload.token
      state.userName = payload.userName
      state.timeout = Date.now()
      state.userId = payload.userId      // 用户id
      state.roleCode = payload.roleCode  // 角色code
      state.regionId = payload.regionId  // 区域Id(运营、运维客户端专用)
    }
  },
  actions: {
    logout(context) {
      context.commit('setStateToken', {})
      localStorage.removeItem('vuex')
      router.push('/login')
    }
  }
}
